package br.ufrj.dcc.engine;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JComboBox;

/**
 * Listener of the whole application.
 * @author Pedro Rougemont
 *
 */
public class AppListener implements ActionListener {

	private Controller controller;
	
	public AppListener(Controller controller2) {		
		super();
		this.controller = controller2;
	}

	public void actionPerformed(ActionEvent e) {
		String comando = e.getActionCommand();
				
		if (comando.equals("open")) {
			FileChooser fc = new FileChooser();
			File file = fc.carregaArquivo();
			controller.setFile(file);	
		}
		else if (comando.equals("execute")) {
			controller.executeMethod();			
		}
		else if (comando.equals("newMethodSelected")) {
			JComboBox comboBox = (JComboBox) e.getSource();
	        String method = (String) comboBox.getSelectedItem();
			controller.setMethod(method);
		}
	}
	
	public void setController(Controller controller){
		this.controller = controller;
	}
}
